#include "Engine.h"

GameInput *GameInput::gameInput;

// Initialize the GameInput
GameInput::GameInput():
            pointerX(-1), 
            pointerY(-1), 
            pointerState(0)            
{
    ClearState();
    gameInput = NULL;
}

// Destroy the GameInput
GameInput::~GameInput()
{
    
}

// Clear current state;
void GameInput::ClearState()
{
    memset(keyState, 0, sizeof(keyState));
	pointerState = POINTER_NONE;
	pointerX = -1;
	pointerY = -1;
}

// Key Event
void GameInput::KeyEvent(int type, int keyCode)
{    
    if (keyCode >= 0 && keyCode <= 255)
    {
        keyState[keyCode] = (type == KEY_DOWN);
    }
}

// Check a key is pressed or not
bool GameInput::IsKeyDown(int keyCode)
{
    return keyState[keyCode];
}

// Return the Global gameInput
GameInput* GameInput::GetGameInput()
{
	if ( gameInput == NULL )
		gameInput = new GameInput();
    return gameInput;
}

void GameInput::PointerEvent(int state, int x, int y)
{
    pointerState = state;
    pointerX = x;
    pointerY = y;
}

// Get Pointer state
int GameInput::GetPointerState()
{
    return pointerState;   
}

